//
//  AppDelegate.swift
//  HDBWeibo
//
//  Created by leidon on 2016/11/17.
//  Copyright © 2016年 BONC. All rights reserved.
//

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?


    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.
        
        sleep(2)
        
        
        
        //1.创建
        window = UIWindow()
        window?.backgroundColor = UIColor.white
        //2.根试图
        window?.rootViewController = HDBMainViewController()
        //3.显示
        window?.makeKeyAndVisible()
 
        setDocDir()
        return true
    }

    func setDocDir() {
        //url
        let url = Bundle.main.url(forResource: "main.json", withExtension: nil)
        
        //从url取出数据 ：NSData?
        let data = NSData.init(contentsOf: url!)
        //写入沙盒 -- 沙盒路径
        let docDirt = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0]
        
        //将“main.json”拼接到 沙盒路径后面
        let jsonPath = (docDirt as NSString).appendingPathComponent("main.json")
        
        //将数据写入沙盒中
        data?.write(toFile: jsonPath, atomically: true)
    }
    
    
    //MARK: 自定义输出格式
    /// 自定义log：文件名、行数、内容
    func HDBLog<T>(_ message : T, file : String = #file, function : String = #function, line : Int = #line){
        //配置：Build setting  -> swift fl -> 输入固定格式:-D DEBUG
        #if DEBUG
            
            let fileName = (file as NSString).lastPathComponent
            print("\(fileName)(\(line))-H:\(message)")
            
        #endif
    }

}

